home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Univers Interactif 3
/
INTERACTIF.BIN
/
mac
/
Planete.net
/
Internet Confirmés_Vrac
/
NetAgent.sea
/
src
/
filelock.c
< prev
next >
Wrap
Text File
|
1992-06-15
|
3KB
|
90 lines
/*
This is an unsupported product. It was developed as part of a study at Ostfold
Regional College, Norway in the spring of 1992.
You use this software at your own risk. Neither the authors nor the Ostfold
Regional College nor any other person or organization except yourself is
responsible for any damage or loss of data derived from the use of this
software. You may distribute this software freely as long as it is in its
original form and all of its files are included. If you make any changes to any
part of this software or the files distributed with it, please state so and do
NOT distribute it under its original name.
*/
#include <stdio.h>
#include <sys/errno.h>
#include <unistd.h>
#include <sys/types.h>
#include <fcntl.h>
extern int errno;
/*
-----------------------------------------------------------------------------
Function name: lock_file()
-----------------------------------------------------------------------------
Parameters: int fd File descriptor.
Return value: none
Called by: reg_user(), nytt(), nytt_ord(), new_words(), new_news(),
hent_nye_innlegg(), do_innlegg, finn_stikkord(), do_user()
Calls: none
Description: Locks the file which is described by fd.
-----------------------------------------------------------------------------
*/
void lock_file(fd)
int fd;
{
struct flock sf;
sf.l_type = F_RDLCK|F_WRLCK;
sf.l_whence = SEEK_SET;
sf.l_start = 0;
sf.l_len = 0;
/* sf.l_pid = 0; */
while(sf.l_type != F_UNLCK) {
if(fcntl(fd, F_GETLK, (int) &sf) == -1) {
perror("fcntl F_GETLK");
exit(1);
}
}
sf.l_type = F_RDLCK|F_WRLCK;
sf.l_whence = SEEK_SET;
sf.l_start = 0;
sf.l_len = 0;
if(fcntl(fd, F_SETLK, (int) &sf) == -1) {
perror("fcntl(F_SETLK)");
exit(1);
}
}
/*
-----------------------------------------------------------------------------
Function name: unlock_file()
-----------------------------------------------------------------------------
Parameters: int fd File descriptor.
Return value: none
Called by: reg_user(), nytt(), nytt_ord(), new_words(), new_news(),
hent_nye_innlegg(), do_innlegg, finn_stikkord(), do_user()
Calls: none
Description: Unlocks the file described by fd.
-----------------------------------------------------------------------------
*/
void unlock_file(fd)
int fd;
{
struct flock sf;
sf.l_type = F_UNLCK;
sf.l_whence = SEEK_SET;
sf.l_start = 0;
sf.l_len = 0;
if(fcntl(fd, F_SETLK, (int) &sf) == -1) {
perror("fcntl(u)(F_SETLK)");
exit(1);
}
}